package model;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
/**   
* @ClassName: PictureFile.java
* @Description: 该类的功能描述
*
* @version: v1.0.0
* @author: eziao
* @date: Mar 26, 2019 3:32:46 PM 
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* Mar 26, 2019     eziao           v1.0.0               修改原因
*/
/**   
* @ClassName: PictureFile.java
* @Description: 该类的功能描述
*
* @version: v1.0.0
* @author: eziao
* @date: Mar 26, 2019 4:14:38 PM 
*
* Modification History:
* Date         Author          Version            Description
*---------------------------------------------------------*
* Mar 26, 2019     eziao           v1.0.0               修改原因
*/
public class PictureFile {
	
	private String imageName;
	private File imageFile;
	private URL imageURL;// 图片地址

	/**   
	* @Function: PictureFile.java
	* @Description: 两个构造方法,对应两个不同的构造参数
	*
	* @param:File imageFile , String imagePath
	* @version: v1.0.0
	* @author: eziao
	* @date: Mar 26, 2019 3:33:46 PM 
	*/
	public PictureFile(File imageFile) {
		this.imageFile = imageFile;
		imageName = imageFile.getName();//赐名
//		try {
//			imageURL = imageFile.toURI().toURL();
//		} catch (MalformedURLException e) {
//			e.printStackTrace();
//		}
		if(imageName.equals("")) {
			imageName = imageFile.getPath();//若该图片无初始名称,则将路径作为该图片名称
		}
	}
	public PictureFile(String imagePath) {
    	this(new File(imagePath));//通过路径获取图片,调用第一个构造方法
    }
    
    /**   
    * @Function: public PictureFile[] listPictures()
    * @Description: 构造可存储图片类型的数组
    *
    * @param: none
    * @return：返回图片类型数组
    *
    * @date: Mar 26, 2019 3:37:57 PM 
    */
    public PictureFile[] listPictures() {
		File[] files = this.imageFile.listFiles();
		if(files == null||files.length == 0) {
			return null;
		}
		PictureFile[] pictureFiles = new PictureFile[files.length];
		for(int i = 0; i<files.length;i++) {
			pictureFiles[i] = new PictureFile(files[i]);
		}
		return pictureFiles;
	}
    
    public URL toURL() {
    	return imageURL;
    }//返回图片地址
    
   //判断是否为可处理图片类型
    public boolean isPicture() {
    	if(imageName.toLowerCase().endsWith(".jpg")||
    	   imageName.toLowerCase().endsWith(".jpge")||
    	   imageName.toLowerCase().endsWith(".png")||
    	   imageName.toLowerCase().endsWith(".bmp")||
    	   imageName.toLowerCase().endsWith(".gif")	) {
    		return true;
    	}
    	return false;
    }
    //判断是否为文件夹
    public boolean isDirectory() {
    	return imageFile.isDirectory();
    }
    
    public boolean isFile() {
    	return imageFile.isFile();
    }
    
    public boolean isHidden() {
    	return imageFile.isHidden();
    }
    
    public long length() {
    	return imageFile.length();
    }
    
    public String toString() {
		return imageName;
	}   
    
 //------------------getting and setting-----------

    public File getImageFile() {
		return imageFile;
	}
    public String getImageName() {
		return imageName;
	}
}

